package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.domain.ProductType;
import cn.wolfcode.trip.base.mapper.ProductMapper;
import cn.wolfcode.trip.base.mapper.ProductTypeMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductService;
import cn.wolfcode.trip.base.service.IProductTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品分类
 */
@Service
public class IProductTypeServiceImpl implements IProductTypeService {
    @Autowired
    private ProductTypeMapper typeMapper;
    @Override
    /**
     * 分类分页操作
     */
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ProductType> list = typeMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<ProductType> listAll() {
        return typeMapper.selectAll();
    }

    @Override
    public void saveOrUpdate(ProductType type) {
        if (type.getId() != null) {
            typeMapper.updateByPrimaryKey(type);
        }else{
            typeMapper.insert(type);
        }
    }

    @Override
    public void delete(Long id) {
        typeMapper.deleteByPrimaryKey(id);
    }
}
